// 导入父类
import defaultConfig from './default-option'
// 树图的默认配置
const treeDefaultOption = {
  left: '10%',
  top: '10%',
  width: '80%',
  height: '80%',
  layout: 'orthogonal',
  orient: 'LR',
  symbol: 'circle',
  symbolSize: 7,
  expandAndCollapse: true,
  roam: false,
  label: {
    fontSize: 12,
    fontWeight: 'normal'
  },
  leaves: {
    label: {
      position: 'right',
      verticalAlign: 'middle',
      align: 'left'
    }
  },
  itemStyle: {
    borderWidth: 1,
    borderType: 'solid'
  }
}
export default class OptionTree extends defaultConfig {
  constructor (otherOption = {}, data = [], showData = []) {
    // 将主题传给父类
    super()
    // 删除转换图形配置
    delete this.defaultConfig.toolbox.feature.magicType
    // 删除xAxis.data属性（以防止报错）
    delete this.defaultConfig.xAxis.data
    // 合并||重新设置默认配置
    this.option = this.setNewStyle(this.setNewStyle({ tooltip: { trigger: 'item', axisPointer: { type: 'none' } } }, otherOption), this.defaultConfig)
    // 给data添加label标签和设置type为tree
    this.option.series = data.map(item => this.setNewStyle(this.setNewStyle({ label: { formatter: '{b}' } }, { label: this.label }), this.setNewStyle({ type: 'tree' }, item)))
    // 添加树图的默认配置
    this.option.series = this.option.series.map(item => this.setNewStyle(treeDefaultOption, item))
  }
}
